import 'package:flutter/material.dart';
import 'package:flutter_oss_aliyun/flutter_oss_aliyun.dart';
import 'package:ls_loading/Type.dart';
import 'package:ls_loading/ls_loading%20copy.dart';

class LsImage extends StatefulWidget {
  String fileId;
  final void Function() onClick;
  LsImage({super.key, required this.fileId, required this.onClick});

  @override
  State<StatefulWidget> createState() {
    return _LsImageState();
  }
}

class _LsImageState extends State<LsImage> {
  String? url;
  @override
  void initState() {
    super.initState();
    Client()
        .getSignedUrl(widget.fileId, process: "image/resize,w_200")
        .then((value) {
      setState(() {
        url = value;
      });
    });
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      width: 200,
      child: Column(children: [
        MouseRegion(
          cursor: SystemMouseCursors.click,
          child: Listener(
            onPointerDown: (event) async {
              widget.onClick();
            },
            child: Container(
                width: 200,
                height: 200,
                decoration: BoxDecoration(
                  border: Border.all(
                      color: Color.fromARGB(255, 210, 210, 210), width: 1),
                ),
                child: url == null
                    ? LsLoading(
                        style: LoadingStyle(
                            color: Colors.blue,
                            strokeWidth: 5,
                            radius: 30,
                            width: 150,
                            height: 150))
                    : Image.network(
                        url!,
                      )),
          ),
        ),
        Container(
          margin: const EdgeInsets.only(top: 10),
          child: const Text(
            '正面像',
            style: TextStyle(fontSize: 12),
          ),
        )
      ]),
    );
  }
}
